<?php
namespace App\DBs\Stock;

use Illuminate\Support\Facades\DB;
use App\DBs\BaseDB as Base;

class BaseDB extends Base
{
    /**
     * 基本DB
     */

    public function __construct()
    {
    }

    /**
     * 获取库视频
     */
    public function getStockOneById($vid)
    {
        $table = 'stock';
        $models = DB::table($table)->where('del',0)
            ->where('id',$vid)
            ->skip(0)->take(1)
            ->orderBy('id','desc')
            ->get();
        return count($models) ? $this->jsonToArr($models[0]) : array();
    }

    /**
     * 获取创单
     */
    public function getPlusOneById($plusId)
    {
        $table = 'stock_plus';
        $models = DB::table($table)->where('del',0)
            ->where('id',$plusId)
            ->skip(0)->take(1)
            ->orderBy('id','desc')
            ->get();
        return count($models) ? $this->jsonToArr($models[0]) : array();
    }

    /**
     * 获取创板
     */
    public function getBoardOneById($boardId)
    {
        $table = 'stock_board';
        $models = DB::table($table)->where('del',0)
            ->where('id',$boardId)
            ->skip(0)->take(1)
            ->orderBy('id','desc')
            ->get();
        return count($models) ? $this->jsonToArr($models[0]) : array();
    }

    /**
     * 获取创板素材
     */
    public function getSourcesByBid($boardId)
    {
        $table = 'stock_board_source';
        $models = DB::table($table)->where('del',0)
            ->where('bid',$boardId)
            ->orderBy('serial','asc')
            ->get();
        return count($models) ? $this->jsonToArr($models) : array();
    }

    /**
     * 获取创板素材
     */
    public function getSourceOne($boardId,$serial)
    {
        $table = 'stock_board_source';
        $models = DB::table($table)->where('del',0)
            ->where('bid',$boardId)
            ->where('serial',$serial)
            ->skip(0)->take(1)
            ->orderBy('serial','asc')
            ->get();
        return count($models) ? $this->jsonToArr($models[0]) : array();
    }

    /**
     * 获取当前创板中，编号最大的素材
     */
    public function getSourceMaxOne($boardId)
    {
        $table = 'stock_board_source';
        $models = DB::table($table)->where('del',0)
            ->where('bid',$boardId)
            ->skip(0)->take(1)
            ->orderBy('serial','desc')
            ->get();
        return count($models) ? $this->jsonToArr($models[0]) : array();
    }

    /**
     * 获取当前创板中，编号最大的素材
     */
    public function getSourceOneById($sourceId)
    {
        $table = 'stock_board_source';
        $models = DB::table($table)->where('del',0)
            ->where('id',$sourceId)
            ->skip(0)->take(1)
            ->orderBy('serial','desc')
            ->get();
        return count($models) ? $this->jsonToArr($models[0]) : array();
    }
}